package com.example.chao.myphotosearch.presenter;

import com.example.chao.myphotosearch.api.HttpRetrofit;
import com.example.chao.myphotosearch.api.HttpSubscribe;
import com.example.chao.myphotosearch.dao.Recommend;
import com.example.chao.myphotosearch.interfaces.SubscriberDoOnNextListener;
import com.example.chao.myphotosearch.view.ISwipeView;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by chao on 2016/3/29.
 */
public class MainFragmentPresenter implements IPresenter<ISwipeView<List<Recommend>>> {
    private List<Recommend> recommends;
    private ISwipeView<List<Recommend>> iSwipeView;
    @Inject
    public MainFragmentPresenter(){
        recommends = new ArrayList<>();
    }

    @Override
    public void onCreate(ISwipeView<List<Recommend>> iView) {
        iSwipeView = iView;
        onViewCreated();
    }

    @Override
    public void onViewCreated() {
        HttpRetrofit.getRecommendModel(0, 8, new HttpSubscribe<List<Recommend>>(new SubscriberDoOnNextListener<List<Recommend>>() {
            @Override
            public void doOnNext(List<Recommend> recommendList) {
                recommends = recommendList;
                iSwipeView.attachView(recommends);
            }
        }));
        iSwipeView.hideRefresh();
    }
}
